class Player
  
  attr_accessor :score, :weapon_power, :hero_shape, :speed, :hp

  def initialize(window)
    @hero_body = CP::Body.new(10.0, 150.0)
    
    hero_shape_array =
      [
        CP::Vec2.new(-33.0, -40.0),
        CP::Vec2.new(-33.0, 40.0),
        CP::Vec2.new(33.0, 40.0),
        CP::Vec2.new(33.0, -40.0)
      ]
      
    @hero_shape = CP::Shape::Poly.new(@hero_body, hero_shape_array, CP::Vec2.new(0,0))
    
    @hero_shape.collision_type = :hero
    
    $space.add_body(@hero_body)
    $space.add_shape(@hero_shape)
    
    
    @ammo = 50
    @hp = 100
    
    #grab image of ship
    @hero_image = Gosu::Image.new(window, "media/hamburger.bmp", false)
    
    #position
    @hero_shape.body.p = CP::Vec2.new(0.0,0.0)
    @hero_shape.body.v = CP::Vec2.new(0.0,0.0)
    
    @hero_shape.body.a = (3*Math::PI/2.0)
    @speed = 1.0
    @score = 0
    @weapon_power = 1.0
  end
  
  # Directly set the position of our Hero
  def warp(vect)
    @hero_shape.body.p = vect
  end
  
  def turn_left
    @hero_shape.body.apply_impulse(-(@hero_shape.body.t.radians_to_vec2 * ((300.0*@speed)/SUBSTEPS)), CP::Vec2.new(0.0, 0.0))
  end
  
  def turn_right
    @hero_shape.body.apply_impulse((@hero_shape.body.t.radians_to_vec2 * ((300.0*@speed)/SUBSTEPS)), CP::Vec2.new(0.0, 0.0))
  end
  
  def accelerate
    @hero_shape.body.apply_force((@hero_shape.body.a.radians_to_vec2 * ((3000.0*@speed)/SUBSTEPS)), CP::Vec2.new(0.0, 0.0))
  end

  def boost
    @hero_shape.body.apply_force((@hero_shape.body.a.radians_to_vec2 * (3000.0)), CP::Vec2.new(0.0, 0.0))
  end
  
  def reverse
    @hero_shape.body.apply_force(-(@hero_shape.body.a.radians_to_vec2 * ((2500.0*@speed)/SUBSTEPS)), CP::Vec2.new(0.0, 0.0))
  end
  
  # keep on screen
  def validate_position
    if (hero_shape.body.p.x.round >= SCREEN_WIDTH-33)
      warp(CP::Vec2.new(SCREEN_WIDTH-33, hero_shape.body.p.y)) 
    end
    
    if (hero_shape.body.p.x.round <= 0+33)
      warp(CP::Vec2.new(0+33, hero_shape.body.p.y))
    end
    
    if (hero_shape.body.p.y.round >= SCREEN_HEIGHT-33)
      warp(CP::Vec2.new(hero_shape.body.p.x, SCREEN_HEIGHT-33))
    end
    
    if (hero_shape.body.p.y.round <= 0+33)
      warp(CP::Vec2.new(hero_shape.body.p.x, 0+33))
    end
  end
  
  def draw
    @hero_image.draw_rot(@hero_shape.body.p.x, @hero_shape.body.p.y, ZOrder::Player, @hero_shape.body.a.radians_to_gosu)
  end

end